home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / MPUTZ4P.C < prev    next >
C/C++ Source or Header  |  1992-06-14  |  7KB  |  173 lines

  1. /* mputz4p.c  -  Decoding image in Z4Plane format to HRAM buffer,
  2.  *               in form of 4 planes. (for UNCHAINED mode).
  3.  *
  4.  * Description:
  5.  *
  6.  *   Uses the following coding method:
  7.  *   Each image contains 4 arrays (one per plane).
  8.  *   Each array has non-determined length, and terminated by row counter.
  9.  *   Line ends by a 0, 0.
  10.  *   Image is coded by the groups:
  11.  *
  12.  *     n pixels literally       (n = 0 - 127)
  13.  *     +-----+---------------------------+
  14.  *     | +n  |  n bytes of pixel values  |
  15.  *     +-----+---------------------------+
  16.  *
  17.  *     n pixels of specified color (n = 3 - 255)
  18.  *     +-----+-----+--------+
  19.  *     |  0  |  n  | color  |
  20.  *     +-----+-----+--------+
  21.  *
  22.  *     skipping n pixels  (n = 1 - 127)
  23.  *     +-----+
  24.  *     | -n  |
  25.  *     +-----+
  26.  *
  27.  *     EOL
  28.  *     +-----+
  29.  *     | 128 |
  30.  *     +-----+
  31.  *
  32.  *   Decoding is directed into the animation buffer, specified by a
  33.  *   segment address (starting offset is assumed to be 0).
  34.  *   Plane interleaving for each buffer is specified by the argument,
  35.  *   given in paragraphs.
  36.  *   Width in bytes of each plane in buffer also must be specified, to
  37.  *   provide the proper increment in case of EOL.
  38.  *
  39.  * Functions:
  40.  *      MputZ4Planes().
  41.  * Portability: BORLANDC
  42.  *                                      (c) erdy 1992
  43.  * $Header: $
  44.  */
  45. #pragma inline
  46. #include "far.h"
  47. #include "vgaprefx.h"
  48. #include "vgadrv.h"
  49. #include "screen.h"
  50.  
  51. #ifndef Z4P_RAMWIDTH
  52. void MputZ4Planes(char far *image,    /* image data ptr */
  53.                   int rows,           /* rows to process */
  54.                   unsigned segment,   /* address segment of planes buffer */
  55.                   unsigned offset,    /* starting offset */
  56.                   unsigned planewidth,/* width of plane buffer,
  57.                                        * MUST BE equal to Npixels/4 */
  58.                   unsigned char planeintl/* plane buffer interleaving, in paragraphs */
  59.                   )
  60. #else   Z4P_RAMWIDTH
  61. void MputZ4Planes(char far *image,    /* image data ptr */
  62.                   int rows,           /* rows to process */
  63.                   unsigned segment,   /* address segment of planes buffer */
  64.                   unsigned offset     /* starting offset */
  65.                   )
  66. #       ifndef Z4P_RAMHEIGHT
  67. #               error Z4P_RAMHEIGHT must be defined
  68. #       endif  Z4P_RAMHEIGHT
  69. #endif  Z4P_RAMWIDTH
  70. {
  71.         /* Charge the registers */
  72.         _ES = segment;
  73.         _DI = offset;                   /* Offset of this image */
  74. #       ifndef Z4P_RAMWIDTH
  75.                 _BX = rows;
  76.                 _DX = planewidth;
  77. #       else   Z4P_RAMWIDTH
  78.                 _DX = rows;
  79. #       endif  Z4P_RAMWIDTH
  80.  
  81. #       ifndef Z4P_RAMHEIGHT
  82.                 _AX = planeintl;
  83. #       endif  Z4P_RAMHEIGHT
  84.  
  85.     asm push ds;
  86.     asm lds si, image;
  87.     asm cld;
  88.         asm push bp;
  89.         asm mov cx, BITPLANES;
  90. PlaneLoop:
  91.         /*
  92.          * Planes loop. CX contains plane counter.
  93.          */
  94.         asm push cx;                    /* Save plane counter */
  95.         asm push di;                    /* Save the initial offset */
  96.  
  97. #       ifndef Z4P_RAMWIDTH
  98.                 asm mov  cx, bx;        /* And store row counter in cx */
  99.                 asm push bx;            /* Save initial row counter */
  100.                 asm push ax;            /* Save plane interleaving */
  101. #       else   Z4P_RAMWIDTH
  102.                 asm mov  cx, dx;        /* And store row counter in cx */
  103. #       endif  Z4P_RAMWIDTH
  104.  
  105.                 /*++++same+++as++uputz4p.c+++*/
  106. RowLoop:
  107.                 /*
  108.                  * Scanlines loop. CX contains nrows.
  109.                  * Scratch registers:
  110.                  *      bx - saving the ram index (di)
  111.                  *      bp - saving the loop counter (cx)
  112.                  */
  113.                 asm mov bx, di;                 /* Save ram index */
  114.                 asm mov bp, cx;                 /* Save loop counter */
  115.                 asm xor ch, ch;                 /* Zero high byte, ch always zero */
  116.                 /* Loop until EOL */
  117.                 asm jmp short LineLoop;         /* Jump over the literal-dealing code */
  118.                                                 /* This tricky is for optimizing jumps */
  119. Literal:
  120.                         asm rep movsb;          /* Copy cx bytes */
  121. LineLoop:
  122.             asm lodsb;              /* al <- ds:[si++]; get next byte */
  123.                         asm mov cl, al;         /* Move code */
  124.  
  125.                         asm or al, al;          /* Query flags */
  126.                         asm jg Literal;         /* al > 0, so literally */
  127.                         asm je short String;    /* al == 0, string or EOL */
  128. Skip:                                           /* Otherwise skipping */
  129.                         asm neg cl;             /* Invert counter */
  130.                         asm jo Eol;             /* Overflow, i.e. neg 128 */
  131.                         asm add di, cx;         /* Advance the index */
  132.                         asm jmp short LineLoop;
  133. String:
  134.                         asm lodsb;              /* Get counter byte */
  135.             asm mov cl, al;        /* Put counter to cl */
  136.                         asm lodsb;              /* Get color byte into al */
  137.                         asm rep stosb;          /* Store cx bytes of al */
  138.                         asm jmp short LineLoop;
  139. Eol:
  140.                 /*--same--as--uputz4p.c---*/
  141.                 asm mov di, bx;                 /* Restore ram index */
  142. #               ifndef Z4P_RAMWIDTH
  143.                         asm add di, dx;         /* Advance ram index to next row */
  144. #               else   Z4P_RAMWIDTH
  145.                         asm add di, Z4P_RAMWIDTH SHR 2;/* Advance ram index to next row */
  146. #               endif  Z4P_RAMWIDTH
  147.  
  148.                 asm mov cx, bp;                 /* Restore row counter */
  149.                 asm loop RowLoop;
  150.  
  151. #       ifndef Z4P_RAMHEIGHT
  152.                 asm pop ax;
  153.                 asm mov bx, es;
  154.                 asm add bx, ax;
  155. #       else   Z4P_RAMHEIGHT
  156.                 asm mov bx, es;
  157.                 asm add bx, (Z4P_RAMHEIGHT*(Z4P_RAMWIDTH SHR 2)) SHR 4;
  158. #       endif  Z4P_RAMHEIGHT
  159.         asm mov es, bx;         /* Advance the ram buffer segment register */
  160.  
  161. #       ifndef Z4P_RAMWIDTH
  162.                 asm pop bx;     /* Restore initial row counter */
  163. #       endif  Z4P_RAMWIDTH
  164.  
  165.         asm pop di;             /* Restore the initial offset */
  166.  
  167.         asm pop cx;
  168.         asm loop PlaneLoop;
  169.  
  170.         asm pop bp;
  171.     asm pop ds;
  172.     return;
  173. }